//
//  CMDBHomeDetailTableVIew.swift
//  CMDB
//
//  Created by 曹桂祥 on 17/4/14.
//  Copyright © 2017年 CMDB. All rights reserved.
//

import UIKit

private let TopicDetailCommentCell = "TopicDetailCommentCell"

class CMDBHomeDetailTableView: CMDBBaseTableView {
    
    var controller : UIViewController?

    lazy var headerView : CMDBDetailHeaderView = CMDBDetailHeaderView.getInstance()
    
    var emptyCommentView: CMDBBaseView = CMDBBaseView.getInstance()
    
    override func setupTableView(){
        super.setupTableView()
        
        self.registerClass(CMDBCommentCell.self, forCellReuseIdentifier:TopicDetailCommentCell)
    }
    
    override func updateHeaderData(data: AnyObject?) {
        
        let detailData   = data as! CMDBDynamicBean
        
        headerView.update(data)
        
        headerView.frame = CGRect(x: 0, y: 0, width: CMDB_Screen_Width, height: headerView.thisHeight)
        
        tableHeaderView  = headerView
        
        let emptyLabel   = UILabel.getInstance()
        
        emptyLabel.text  = "请您留下精彩的评论"
        
        emptyLabel.textColor = word54Color
        
        emptyLabel.sizeToFit()
        
        emptyCommentView.addSubview(emptyLabel)
        
        emptyLabel.snp_makeConstraints { (make) in
            make.centerX.equalTo(0)
            make.centerY.equalTo(0)
        }
        
        addSubview(emptyCommentView)
        
        if !((detailData.comments?.count) != nil){
            
            emptyCommentView.hidden = false
            emptyCommentView.frame  = CGRect(x: 0, y: CGRectGetMaxY(headerView.frame), width: CMDB_Screen_Width, height: CMDB_Screen_Height - headerView.thisHeight - 64 - 45)
            
        }else{
            
            emptyCommentView.hidden = true
            
        }
        
    }
    
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        
        return dequeCellAndLoadContentFromAdapter(tableViewAdapterArray![indexPath.row] , indexPath: indexPath, tableView: self, controller: self.controller,cellReuseIdentifier : TopicDetailCommentCell)
        
    }
    
    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        
        let viewModel = tableViewdataArray![indexPath.row] as! CMDBCommentBean
        
        return viewModel.cellHeight
    }


}
